package com.hadwinling.blog.controller;

import com.hadwinling.blog.entity.Admin;
import com.hadwinling.blog.entity.Money;
import com.hadwinling.blog.service.MoneyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @author HadwinLing
 * @version V1.0
 * @Package com.hadwinling.blog.controller
 * @date 2020/8/31 10:44
 */
@Controller
public class UserEchartsController {
    @Autowired
    private MoneyService moneyService;

    /**
     * 找到echarts的数据
     * @param request
     * @return
     */
    @PostMapping("/user/show")
    @ResponseBody
    public List<Money> show(HttpServletRequest request){
        Admin currUser = (Admin) request.getSession().getAttribute("currUser");
        List<Money> moneyList = moneyService.selectTagByAdminidAndState(currUser.getId(), 1);
//        System.out.println("1:"+moneyList);
        return moneyList;
    }


    /**
     * 跳转到数据统计页面
     * @param request
     * @param model
     * @return
     */
    @GetMapping("/user/echarts")
    public String toShowEchartsPage(HttpServletRequest request, Model model){
        Admin currUser = (Admin) request.getSession().getAttribute("currUser");
        List<Money> moneyList = moneyService.selectTagByAdminidAndState(currUser.getId(), 1);
        model.addAttribute("moneyList",moneyList);
        int money = moneyService.sumMoneyByAdminid(currUser.getId());
        model.addAttribute("money",money);
        return "UserCenter/charts";
    }
}
